const { defineConfig } = require('@vue/cli-service')
const path = require("path");
const webpack = require('webpack');

const mode = process.env.mode; // 获取全局变量
var target = "", webSource = { mode: '' }, resourceVersion = 11;// 正式环境版本号：11
switch (mode) {
  case 'dev':
    webSource.mode = 'dev'
    // target = 'http://192.168.10.37:5300'
    target = 'http://192.168.10.34:80' // 测试环境
    // target = 'http://192.168.10.88:7100' // lxf
    // target = "https://ul960hm5971.vicp.fun" // 济南
    break;
  case 'master':
    webSource.mode = 'master'
    target = "https://zhixiang.quanxun-iot.com"
    break;
  default:
    target = "https://zhixiang.quanxun-iot.com"
    break;
}

module.exports = defineConfig({
  publicPath: ``, // 发布目录
  outputDir: `dist`, // 生成文件目录
  indexPath: "index.html",
  filenameHashing: true,
  productionSourceMap: false,
  lintOnSave: false, // 设置是否在开发环境下每次保存代码时都启用 eslint验证。 false:关闭
  transpileDependencies: true,
  chainWebpack: (config) => {
    config.resolve.alias.set("@", path.join(__dirname, "./src")); // @scss是你取的静态资源路径别名// 若需要配置多个别名，后续紧跟着设置set即可
    config.module.rule('vue').test(/\.vue$/).use('style-vw-loader').loader('style-vw-loader').options({ // 设置postcss-px-to-viewport的行内样式生效
      unitToConvert: 'px',
      viewportWidth: 375, // 按照设计图来 必须和postcss.config文件尺寸一致
      unitPrecision: 5,
      viewportUnit: 'vw',
      fontViewportUnit: 'vw',
      minPixelValue: 1
    })
  },
  configureWebpack: {//暴露对象出去,让页面使用
    plugins: [
      new webpack.DefinePlugin({
        'WEB_SOURCE': JSON.stringify(webSource),
        'RESOURCE_VERSION': resourceVersion // 页面版本号
      }),
    ]
  },

  devServer: {
    open: false,
    host: "0.0.0.0",
    port: 7090,
    https: true,
    hot: true,
    client: {
      overlay: false,
    },
    proxy: {
      "/ums/": {
        target,
        changeOrigin: true,
        secure: false,
      },
      "/eas": {
        target,
        changeOrigin: true,
        secure: false,
      },
      "/mnc": {
        target,
        changeOrigin: true,
        secure: false,
      },
    },
  },
})
